import { Controller, Get, Post,   Res ,Body, Patch, Param, Delete,UseInterceptors,UploadedFile } from '@nestjs/common';
import { UploadService } from './upload.service';
import { CreateUploadDto } from './dto/create-upload.dto';
import { UpdateUploadDto } from './dto/update-upload.dto';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express/multer';
import type { Response } from 'express'
import { join } from 'path'
import { ApiTags, ApiOperation } from '@nestjs/swagger/dist'
@Controller('upload')
  @ApiTags('上传文件相关')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}
  @ApiOperation({summary:'使用formData上传文件',description:"使用formData上传文件"})
  @Post('album')
  @UseInterceptors(FileInterceptor('file')) //UseInterceptors这个装饰器用来处理文件 -- 传入参数FileInterceptor是读取字段名
  upload(@UploadedFile() file:Express.Multer.File) {//使用UploadedFile来接收file文件
    console.log(file, 'file');
    return file

  }

   // 文件下载
  @Get('export')
  download(@Res() res: Response) {
    const fileName = '1677586452654.jpg'
    //正常应该是从数据库里获取地址
    const url = join(__dirname, `../images/${fileName}`)
     res.download(url)
   }

}
